package cn.wenhaha.common.bean.entity;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 时间枚举
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2022-12-17 18:18
 */
public enum TimeEntity {
    DAY(0),
    WEEK(1),
    MONTH(2),
    SEASON(3),
    YEAR(4) ;

    private  final String format="yyyy-MM-dd";

    private  final Integer code;

    public static  List<TimeEntity> list(){
        return  Arrays.asList(values());
    }

    TimeEntity(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }



    public String startDate(){
        Date date = new Date();
        switch (this){
            case WEEK:
                DateTime dateTime = DateUtil.beginOfWeek(date);
                return dateTime.toString(format);
            case MONTH:
                return DateUtil.beginOfMonth(date).toString(format);
            case SEASON:
                return DateUtil.beginOfQuarter(date).toString(format);
            case YEAR:
                return DateUtil.beginOfYear(date).toString(format);
            default:
                return DateUtil.formatDate(date);
        }
    }

    public String endDate(){
        Date date = new Date();
        switch (this){
            case WEEK:
                return DateUtil.endOfWeek(date).toString(format);
            case MONTH:
                return  DateUtil.endOfMonth(date).toString(format);
            case SEASON:
                return DateUtil.endOfQuarter(date).toString(format);
            case YEAR:
                return DateUtil.endOfYear(date).toString(format);
            default:
                return DateUtil.formatDate(date);
        }
    }
}
